# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.pro>

_realname=ujson
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=4.0.2
pkgrel=1
pkgdesc="Ultra fast JSON encoder and decoder for Python (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://github.com/ultrajson/ultrajson"
license=('custom')
depends=("${MINGW_PACKAGE_PREFIX}-python")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools-scm"
             "${MINGW_PACKAGE_PREFIX}-python-pip")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-six"
              "${MINGW_PACKAGE_PREFIX}-python-pytest")
source=("ultrajson-${pkgver}.tar.gz"::"${url}/archive/${pkgver}.tar.gz")
sha256sums=('ef7d8604fc035a2b9a18f532235aa2905244b041cc6b36a503162ac2a311a7c2')

prepare() {
  cd "${srcdir}"
  rm -rf "python-build-${CARCH}" | true
  cp -r "ultrajson-${pkgver}" "python-build-${CARCH}"
}

build() {
  msg "Python build for ${CARCH}"
  cd "${srcdir}/python-build-${CARCH}"
  SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver \
    ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  cd "${srcdir}/python-build-${CARCH}"
  local PYTHONVERSION="$(${MINGW_PREFIX}/bin/python -c 'import sys; print("{}.{}".format(sys.version_info.major, sys.version_info.minor))')"
  PYTHONPATH="build/lib.mingw-${PYTHONVERSION}" pytest
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver \
    ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" -O1 --skip-build
  install -Dm644 LICENSE.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}

# vim: ts=2 sw=2 et:
